package com.pigdroid.adbsqlite.jdbc;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.RowIdLifetime;
import java.sql.SQLException;

import com.pigdroid.adbsqlite.CSVIterator;

public class ADBSQLiteDatabaseMetadata implements DatabaseMetaData {

	private ADBSQLiteConnection connection;

	public ADBSQLiteDatabaseMetadata(ADBSQLiteConnection adbsqLiteConnection) {
		this.connection = adbsqLiteConnection;
	}

	public boolean isWrapperFor(Class<?> arg0) throws SQLException {
		return false;
	}

	public <T> T unwrap(Class<T> arg0) throws SQLException {
		try {
			return arg0.newInstance();
		} catch (Exception e) {
			throw new SQLException(e);
		}
	}

	public boolean allProceduresAreCallable() throws SQLException {
		return false;
	}

	public boolean allTablesAreSelectable() throws SQLException {
		return true;
	}

	public boolean autoCommitFailureClosesAllResultSets() throws SQLException {
		return false;
	}

	public boolean dataDefinitionCausesTransactionCommit() throws SQLException {
		return true;
	}

	public boolean dataDefinitionIgnoredInTransactions() throws SQLException {
		return false;
	}

	public boolean deletesAreDetected(int arg0) throws SQLException {
		return true;
	}

	public boolean doesMaxRowSizeIncludeBlobs() throws SQLException {
		return false;
	}

	public boolean generatedKeyAlwaysReturned() throws SQLException {
		return false;
	}

	public ResultSet getAttributes(String catalog, String schemaPattern,
			String typeNamePattern, String attributeNamePattern)
			throws SQLException {
		return new ADBSQLiteResultSet();
	}

	public ResultSet getBestRowIdentifier(String arg0, String arg1,
			String arg2, int arg3, boolean arg4) throws SQLException {
		return new ADBSQLiteResultSet();
	}

	public String getCatalogSeparator() throws SQLException {
		return " ";
	}

	public String getCatalogTerm() throws SQLException {
		return "schema";
	}

	public ResultSet getCatalogs() throws SQLException {
		String ret = "TABLE_CAT\n" + connection.getSchema();
		return new ADBSQLiteResultSet(connection, new CSVIterator(ret));
	}

	public ResultSet getClientInfoProperties() throws SQLException {
		return new ADBSQLiteResultSet();
	}

	public ResultSet getColumnPrivileges(String arg0, String arg1, String arg2,
			String arg3) throws SQLException {
		return new ADBSQLiteResultSet();
	}

	public ResultSet getColumns(String catalog, String schemaPattern,
			String tableNamePattern, String columnNamePattern)
			throws SQLException {
		// TODO
		return new ADBSQLiteResultSet();
	}

	public Connection getConnection() throws SQLException {
		return connection;
	}

	public ResultSet getCrossReference(String arg0, String arg1, String arg2,
			String arg3, String arg4, String arg5) throws SQLException {
		// TODO
		return new ADBSQLiteResultSet();
	}

	public int getDatabaseMajorVersion() throws SQLException {
		return 0;
	}

	public int getDatabaseMinorVersion() throws SQLException {
		return 0;
	}

	public String getDatabaseProductName() throws SQLException {
		return "sqlite3.... I hope";
	}

	public String getDatabaseProductVersion() throws SQLException {
		return "sqlite3.... I hope";
	}

	public int getDefaultTransactionIsolation() throws SQLException {
		return 0;
	}

	public int getDriverMajorVersion() {
		return 0;
	}

	public int getDriverMinorVersion() {
		return 0;
	}

	public String getDriverName() throws SQLException {
		return "Pigdroid ADB SQLite Driver";
	}

	public String getDriverVersion() throws SQLException {
		return "Pigdroid ADB SQLite Driver";
	}

	public ResultSet getExportedKeys(String arg0, String arg1, String arg2)
			throws SQLException {
		return new ADBSQLiteResultSet();
	}

	public String getExtraNameCharacters() throws SQLException {
		return "";
	}

	public ResultSet getFunctionColumns(String arg0, String arg1, String arg2,
			String arg3) throws SQLException {
		return new ADBSQLiteResultSet();
	}

	public ResultSet getFunctions(String arg0, String arg1, String arg2)
			throws SQLException {
		return new ADBSQLiteResultSet();
	}

	public String getIdentifierQuoteString() throws SQLException {
		return "\"";
	}

	public ResultSet getImportedKeys(String arg0, String arg1, String arg2)
			throws SQLException {
		return new ADBSQLiteResultSet();
	}

	public ResultSet getIndexInfo(String arg0, String arg1, String arg2,
			boolean arg3, boolean arg4) throws SQLException {
		return new ADBSQLiteResultSet();
	}

	public int getJDBCMajorVersion() throws SQLException {
		return 0;
	}

	public int getJDBCMinorVersion() throws SQLException {
		return 0;
	}

	public int getMaxBinaryLiteralLength() throws SQLException {
		return 0;
	}

	// TODO check this values

	public int getMaxCatalogNameLength() throws SQLException {
		return 32;
	}

	public int getMaxCharLiteralLength() throws SQLException {
		return Integer.MAX_VALUE;
	}

	public int getMaxColumnNameLength() throws SQLException {
		return 32;
	}

	public int getMaxColumnsInGroupBy() throws SQLException {
		return 32;
	}

	public int getMaxColumnsInIndex() throws SQLException {
		return 32;
	}

	public int getMaxColumnsInOrderBy() throws SQLException {
		return 32;
	}

	public int getMaxColumnsInSelect() throws SQLException {
		return Integer.MAX_VALUE;
	}

	public int getMaxColumnsInTable() throws SQLException {
		return Integer.MAX_VALUE;
	}

	public int getMaxConnections() throws SQLException {
		return 1;
	}

	public int getMaxCursorNameLength() throws SQLException {
		return 32;
	}

	public int getMaxIndexLength() throws SQLException {
		return 32;
	}

	public int getMaxProcedureNameLength() throws SQLException {
		return 0;
	}

	public int getMaxRowSize() throws SQLException {
		return Integer.MAX_VALUE;
	}

	public int getMaxSchemaNameLength() throws SQLException {
		return 32;
	}

	public int getMaxStatementLength() throws SQLException {
		return Integer.MAX_VALUE;
	}

	public int getMaxStatements() throws SQLException {
		return Integer.MAX_VALUE;
	}

	public int getMaxTableNameLength() throws SQLException {
		return Integer.MAX_VALUE;
	}

	public int getMaxTablesInSelect() throws SQLException {
		return Integer.MAX_VALUE;
	}

	public int getMaxUserNameLength() throws SQLException {
		return 32;
	}

	public String getNumericFunctions() throws SQLException {
		return "";
	}

	public ResultSet getPrimaryKeys(String arg0, String arg1, String arg2)
			throws SQLException {
		return new ADBSQLiteResultSet();
	}

	public ResultSet getProcedureColumns(String arg0, String arg1, String arg2,
			String arg3) throws SQLException {
		return new ADBSQLiteResultSet();
	}

	public String getProcedureTerm() throws SQLException {
		return "procedure";
	}

	public ResultSet getProcedures(String arg0, String arg1, String arg2)
			throws SQLException {
		String ret = "PROCEDURE_CAT|PROCEDURE_SCHEM|PROCEDURE_NAME|REMARKS|PROCEDURE_TYPE|SPECIFIC_NAME";
		return new ADBSQLiteResultSet(connection, new CSVIterator(ret));
	}

	public ResultSet getPseudoColumns(String arg0, String arg1, String arg2,
			String arg3) throws SQLException {
		return new ADBSQLiteResultSet();
	}

	public int getResultSetHoldability() throws SQLException {
		return 0;
	}

	public RowIdLifetime getRowIdLifetime() throws SQLException {
		return RowIdLifetime.ROWID_UNSUPPORTED;
	}

	public String getSQLKeywords() throws SQLException {
		return "";
	}

	public int getSQLStateType() throws SQLException {
		return DatabaseMetaData.sqlStateSQL;
	}

	public String getSchemaTerm() throws SQLException {
		return "schema";
	}

	public ResultSet getSchemas() throws SQLException {
		String ret = "TABLE_SCHEM|TABLE_CATALOG\n" + connection.getSchema()
				+ "|*null*";
		return new ADBSQLiteResultSet(connection, new CSVIterator(ret));
	}

	public ResultSet getSchemas(String arg0, String arg1) throws SQLException {
		return getSchemas();
	}

	public String getSearchStringEscape() throws SQLException {
		return "_";
	}

	public String getStringFunctions() throws SQLException {
		return "";
	}

	public ResultSet getSuperTables(String arg0, String arg1, String arg2)
			throws SQLException {
		return getTables(null, null, null, null);
	}

	public ResultSet getSuperTypes(String arg0, String arg1, String arg2)
			throws SQLException {
		return new ADBSQLiteResultSet();
	}

	public String getSystemFunctions() throws SQLException {
		return "";
	}

	public ResultSet getTablePrivileges(String arg0, String arg1, String arg2)
			throws SQLException {
		return new ADBSQLiteResultSet();
	}

	public ResultSet getTableTypes() throws SQLException {
		String csv = "TABLE_TYPE/nTABLE";
		return new ADBSQLiteResultSet(connection, new CSVIterator(csv));
	}

	public ResultSet getTables(String catalog, String schemaPattern,
			String tableNamePattern, String[] types) throws SQLException {
		String query = "select null as TABLE_CAT, null as TABLE_SCHEM, tbl_name as TABLE_NAME, 'table' as TABLE_TYPE, tbl_name as REMARKS, null as TYPE_CAT, null as TYPE_SCHEM, null as SELF_REFERENCING_COL_NAME, null as REF_GENERATION FROM sqlite_master WHERE type = 'table'";
		CSVIterator csv = connection.getHelper().executeQuery(query);
		return new ADBSQLiteResultSet(connection, csv);
	}

	public String getTimeDateFunctions() throws SQLException {
		return "";
	}

	public ResultSet getTypeInfo() throws SQLException {
		return new ADBSQLiteResultSet();
	}

	public ResultSet getUDTs(String arg0, String arg1, String arg2, int[] arg3)
			throws SQLException {
		return new ADBSQLiteResultSet();
	}

	public String getURL() throws SQLException {
		return connection.getURL();
	}

	public String getUserName() throws SQLException {
		return "";
	}

	public ResultSet getVersionColumns(String arg0, String arg1, String arg2)
			throws SQLException {
		return new ADBSQLiteResultSet();
	}

	public boolean insertsAreDetected(int arg0) throws SQLException {
		return false;
	}

	public boolean isCatalogAtStart() throws SQLException {
		return false;
	}

	public boolean isReadOnly() throws SQLException {
		return false;
	}

	public boolean locatorsUpdateCopy() throws SQLException {
		return false;
	}

	public boolean nullPlusNonNullIsNull() throws SQLException {
		return false;
	}

	public boolean nullsAreSortedAtEnd() throws SQLException {
		return false;
	}

	public boolean nullsAreSortedAtStart() throws SQLException {
		return false;
	}

	public boolean nullsAreSortedHigh() throws SQLException {
		return false;
	}

	public boolean nullsAreSortedLow() throws SQLException {
		return false;
	}

	public boolean othersDeletesAreVisible(int arg0) throws SQLException {
		return false;
	}

	public boolean othersInsertsAreVisible(int arg0) throws SQLException {
		return false;
	}

	public boolean othersUpdatesAreVisible(int arg0) throws SQLException {
		return false;
	}

	public boolean ownDeletesAreVisible(int arg0) throws SQLException {
		return false;
	}

	public boolean ownInsertsAreVisible(int arg0) throws SQLException {
		return false;
	}

	public boolean ownUpdatesAreVisible(int arg0) throws SQLException {
		return false;
	}

	public boolean storesLowerCaseIdentifiers() throws SQLException {
		return false;
	}

	public boolean storesLowerCaseQuotedIdentifiers() throws SQLException {
		return false;
	}

	public boolean storesMixedCaseIdentifiers() throws SQLException {
		return false;
	}

	public boolean storesMixedCaseQuotedIdentifiers() throws SQLException {
		return false;
	}

	public boolean storesUpperCaseIdentifiers() throws SQLException {
		return false;
	}

	public boolean storesUpperCaseQuotedIdentifiers() throws SQLException {
		return false;
	}

	public boolean supportsANSI92EntryLevelSQL() throws SQLException {
		return false;
	}

	public boolean supportsANSI92FullSQL() throws SQLException {
		return false;
	}

	public boolean supportsANSI92IntermediateSQL() throws SQLException {
		return false;
	}

	public boolean supportsAlterTableWithAddColumn() throws SQLException {
		return false;
	}

	public boolean supportsAlterTableWithDropColumn() throws SQLException {
		return false;
	}

	public boolean supportsBatchUpdates() throws SQLException {
		return false;
	}

	public boolean supportsCatalogsInDataManipulation() throws SQLException {
		return false;
	}

	public boolean supportsCatalogsInIndexDefinitions() throws SQLException {
		return false;
	}

	public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException {
		return false;
	}

	public boolean supportsCatalogsInProcedureCalls() throws SQLException {
		return false;
	}

	public boolean supportsCatalogsInTableDefinitions() throws SQLException {
		return false;
	}

	public boolean supportsColumnAliasing() throws SQLException {
		return false;
	}

	public boolean supportsConvert() throws SQLException {
		return false;
	}

	public boolean supportsConvert(int arg0, int arg1) throws SQLException {
		return false;
	}

	public boolean supportsCoreSQLGrammar() throws SQLException {
		return false;
	}

	public boolean supportsCorrelatedSubqueries() throws SQLException {
		return false;
	}

	public boolean supportsDataDefinitionAndDataManipulationTransactions()
			throws SQLException {
		return false;
	}

	public boolean supportsDataManipulationTransactionsOnly()
			throws SQLException {
		return false;
	}

	public boolean supportsDifferentTableCorrelationNames() throws SQLException {
		return false;
	}

	public boolean supportsExpressionsInOrderBy() throws SQLException {
		return false;
	}

	public boolean supportsExtendedSQLGrammar() throws SQLException {
		return false;
	}

	public boolean supportsFullOuterJoins() throws SQLException {
		return false;
	}

	public boolean supportsGetGeneratedKeys() throws SQLException {
		return false;
	}

	public boolean supportsGroupBy() throws SQLException {
		return false;
	}

	public boolean supportsGroupByBeyondSelect() throws SQLException {
		return false;
	}

	public boolean supportsGroupByUnrelated() throws SQLException {
		return false;
	}

	public boolean supportsIntegrityEnhancementFacility() throws SQLException {
		return false;
	}

	public boolean supportsLikeEscapeClause() throws SQLException {
		return false;
	}

	public boolean supportsLimitedOuterJoins() throws SQLException {
		return false;
	}

	public boolean supportsMinimumSQLGrammar() throws SQLException {
		return false;
	}

	public boolean supportsMixedCaseIdentifiers() throws SQLException {
		return false;
	}

	public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException {
		return false;
	}

	public boolean supportsMultipleOpenResults() throws SQLException {
		return false;
	}

	public boolean supportsMultipleResultSets() throws SQLException {
		return false;
	}

	public boolean supportsMultipleTransactions() throws SQLException {
		return false;
	}

	public boolean supportsNamedParameters() throws SQLException {
		return false;
	}

	public boolean supportsNonNullableColumns() throws SQLException {
		return false;
	}

	public boolean supportsOpenCursorsAcrossCommit() throws SQLException {
		return false;
	}

	public boolean supportsOpenCursorsAcrossRollback() throws SQLException {
		return false;
	}

	public boolean supportsOpenStatementsAcrossCommit() throws SQLException {
		return false;
	}

	public boolean supportsOpenStatementsAcrossRollback() throws SQLException {
		return false;
	}

	public boolean supportsOrderByUnrelated() throws SQLException {
		return false;
	}

	public boolean supportsOuterJoins() throws SQLException {
		return false;
	}

	public boolean supportsPositionedDelete() throws SQLException {
		return false;
	}

	public boolean supportsPositionedUpdate() throws SQLException {
		return false;
	}

	public boolean supportsResultSetConcurrency(int arg0, int arg1)
			throws SQLException {
		return false;
	}

	public boolean supportsResultSetHoldability(int arg0) throws SQLException {
		return false;
	}

	public boolean supportsResultSetType(int arg0) throws SQLException {
		return false;
	}

	public boolean supportsSavepoints() throws SQLException {
		return false;
	}

	public boolean supportsSchemasInDataManipulation() throws SQLException {
		return false;
	}

	public boolean supportsSchemasInIndexDefinitions() throws SQLException {
		return false;
	}

	public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException {
		return false;
	}

	public boolean supportsSchemasInProcedureCalls() throws SQLException {
		return false;
	}

	public boolean supportsSchemasInTableDefinitions() throws SQLException {
		return false;
	}

	public boolean supportsSelectForUpdate() throws SQLException {
		return false;
	}

	public boolean supportsStatementPooling() throws SQLException {
		return false;
	}

	public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException {
		return false;
	}

	public boolean supportsStoredProcedures() throws SQLException {
		return false;
	}

	public boolean supportsSubqueriesInComparisons() throws SQLException {
		return false;
	}

	public boolean supportsSubqueriesInExists() throws SQLException {
		return false;
	}

	public boolean supportsSubqueriesInIns() throws SQLException {
		return false;
	}

	public boolean supportsSubqueriesInQuantifieds() throws SQLException {
		return false;
	}

	public boolean supportsTableCorrelationNames() throws SQLException {
		return false;
	}

	public boolean supportsTransactionIsolationLevel(int arg0)
			throws SQLException {
		return false;
	}

	public boolean supportsTransactions() throws SQLException {
		return false;
	}

	public boolean supportsUnion() throws SQLException {
		return false;
	}

	public boolean supportsUnionAll() throws SQLException {
		return false;
	}

	public boolean updatesAreDetected(int arg0) throws SQLException {
		return false;
	}

	public boolean usesLocalFilePerTable() throws SQLException {
		return false;
	}

	public boolean usesLocalFiles() throws SQLException {
		return false;
	}

}
